define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'koudan/log/index' + location.search,
                    add_url: 'koudan/log/add',
                    edit_url: 'koudan/log/edit',
                    del_url: 'koudan/log/del',
                    multi_url: 'koudan/log/multi',
                    import_url: 'koudan/log/import',
                    table: 'koudan_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                queryParams:function(params){
                    var filter = JSON.parse(params.filter);
                    var op = JSON.parse(params.op);
                    var uid = Fast.api.query('uid');  
                    var eid = Fast.api.query('ids');  
                    console.log(uid)
                    if (uid) {
                          filter.user_id = uid;
                          op.extensionId = '=';
                          filter.extension_id = eid;
                          op.extension_id = '=';
                          params.filter = JSON.stringify(filter);
                          params.op = JSON.stringify(op);
                    }
                    return params;
                  
                },
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_id', title: __('Order_id'), operate: 'LIKE'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        // {field: 'order.order_id', title: __('Order.order_id'), operate: 'LIKE'},
                        // {field: 'order.type', title: __('Order.type')},
                        {field: 'order.type', title: __('Type'),  searchList:{"0":"付费测试","1":"完整解读","2":"只看结果","3":"人工解读","4":"赠TA测","5":"补差价","6":"企业团体"}, formatter: Table.api.formatter.normal},
                        {field: 'order.url', title: __('Url'), operate: false, formatter: Table.api.formatter.url},
                        {field: 'order.qrcode', title: __('Image'), operate: false, formatter: function(value,row,index){
                            
                            return '<a href="'+value+'" download="" style="text-decoration:none;color:#333;"><img src="'+value+'" alt="" style="width:35px;height:35px;"/><span style="font-size:8px;">点击下载</span></a>';
                        }},
                        
                        
                        {field: 'order.amount', title: __('Order.amount'), operate:'BETWEEN'},
                        {field: 'order.payamount', title: __('Order.payamount'), operate:'BETWEEN'},
                        {field: 'order.paytype_text', title: __('Order.paytype'),operate: 'LIKE'},
                        {field: 'order.paytime', title: __('Order.paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.status', title: __('Order.status'), searchList: {"created":__('Created'),"paid":__('Paid'),"expired":__('Expired')}, formatter: Table.api.formatter.status},
                        {field: 'order.updatetime', title: __('Order.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        
                        
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
